#ifndef __TM1638_H__
#define __TM1638_H__

/* Includes ------------------------------------------------------------------*/
#include "at32f403a_407_wk_config.h"

/* private includes ----------------------------------------------------------*/
/* add user code begin private includes */
#include "at32f403a_407_board.h"
/* add user code end private includes */

extern uint8_t DispTab[4];

extern uint8_t Update_disp_flg;

#define TM1638_STB                 PBout(1)
#define TM1638_CLK                 PBout(0)
                              
#define TM1638_DIO_IN              at32_gpio_init_mode(GPIOC,GPIO_PINS_5,GPIO_MODE_INPUT )
#define TM1638_DIO_OUT             at32_gpio_init_mode(GPIOC,GPIO_PINS_5,GPIO_MODE_OUTPUT )

#define TM1638_DIO_DataOUT         PCout(5)
#define TM1638_DIO_DataIN          PCin(5)



//地址命令设置
#define TM1638_GRID1  0xc0
#define TM1638_GRID2  0xc1
#define TM1638_GRID3  0xc2
#define TM1638_GRID4  0xc3
#define TM1638_GRID5  0xc4
#define TM1638_GRID6  0xc5
#define TM1638_GRID7  0xc6
#define TM1638_GRID8  0xc7

#define TM1638_GRID9  0xc8
#define TM1638_GRID10 0xc9
#define TM1638_GRID11 0xca
#define TM1638_GRID12 0xcb
#define TM1638_GRID13 0xcc
#define TM1638_GRID14 0xcd
#define TM1638_GRID15 0xce
#define TM1638_GRID16 0xcf


//数据命令设置
/*
#define 0x40   //写数据到显示寄存器
#define 0x42   //读键扫数据
#define 0x40   //自动地址增加
#define 0x44   //固定地址
#define 0x40   //普通模式
#define 0x48   //测试模式
*/

//显示
/*
#define 0x80   //显示关
#define 0x88   //显示开
*/
#define SysBlueLed(s)        Digital_led(8,1,s)
#define NetRedLed(s)         Digital_led(8,2,s)
#define PwrBlueLed(s)        Digital_led(8,3,s)
#define PwrRedLed(s)         Digital_led(8,4,s)
#define RS485BlueLed(s)      Digital_led(8,5,s)
#define GSMRedLed(s)         Digital_led(8,6,s)
#define NetLinkBlueLed(s)    Digital_led(8,7,s)
#define reserved1(s)         Digital_led(8,8,s)

#define ExchangerBlueLed(s)  Digital_led(9,1,s)
#define reserved2(s)         Digital_led(9,2,s)
#define Camera1BlueLed(s)    Digital_led(10,1,s)
#define reserved3(s)         Digital_led(10,2,s)

#define Camera2BlueLed(s)    Digital_led(10,3,s)
#define reserved4(s)         Digital_led(10,4,s)
#define Camera3BlueLed(s)    Digital_led(10,5,s)
#define reserved5(s)         Digital_led(10,6,s)
#define Camera4BlueLed(s)    Digital_led(10,7,s)
#define reserved6(s)         Digital_led(10,8,s)
#define reserved7(s)         Digital_led(11,1,s)
#define reserved8(s)         Digital_led(11,2,s)



#define LED1_BLUE(s)        Digital_led(8,1,s)//LED1蓝灯
#define LED1_RED(s)         Digital_led(8,2,s)//LED1红灯


#define LED2_BLUE(s)        Digital_led(8,3,s)//LED2蓝灯
#define LED2_RED(s)         Digital_led(8,4,s)//LED2红灯


#define LED3_BLUE(s)              Digital_led(8,5,s)//LED3蓝灯
#define LED3_RED(s)         Digital_led(8,6,s)//LED3红灯


#define LED4_BLUE(s)            Digital_led(8,7,s)//LED4蓝灯
#define LED4_RED(s)         Digital_led(8,8,s)//LED4红灯

#define LED5_BLUE(s)              Digital_led(9,1,s)//LED5蓝灯
#define LED5_RED(s)         Digital_led(9,2,s)//LED5红灯


#define LED6_BLUE(s)            Digital_led(10,1,s)//LED6蓝灯
#define LED6_RED(s)         Digital_led(10,2,s)//LED6红灯


#define LED7_BLUE(s)            Digital_led(10,3,s)//LED7蓝灯
#define LED7_RED(s)         Digital_led(10,4,s)//LED7红灯


#define LED8_BLUE(s)            Digital_led(10,5,s)//LED8蓝灯
#define LED8_RED(s)         Digital_led(10,6,s)//LED8红灯


#define LED9_BLUE(s)            Digital_led(10,7,s)//LED9蓝灯
#define LED9_RED(s)         Digital_led(10,8,s)//LED9红灯


#define LED10_BLUE(s)       Digital_led(11,1,s)//LED10蓝灯
#define LED10_RED(s)        Digital_led(11,2,s)//LED10红灯


void TM1638_Read_key(uint8_t *KeyValue);
void TM1638_Init(void);
void dispclear(uint8_t n,uint8_t m);
void Flicker(uint8_t n);
void display_led(uint8_t dig,uint8_t dat);
void display(uint8_t dig,uint8_t dat);
void DigitalTube_led(uint8_t dig,uint8_t Data,uint8_t onoff);
void UpdateDisp(void);
void Write_DATA(uint8_t add,uint8_t DATA);
#endif

